package com.sh.data.engine.domain.integration.offline.model.enums;

import java.util.Objects;

/**
 * @Author: zigui.zdf @Date: 2022/6/29 16:41:44 @Description:
 */
public enum OfflineSyncReplaceRuleEnum {
    INSERT_OVERWRITE(1, "写入前清理已有数据"),
    INSERT_INTO(2, "写入前保留已有数据"),
    REPLACE_BY_NAME(3, "同名覆盖"),
    IGNORE_BY_NAME(4, "同名忽略"),
    REPLACE_BY_PK(5, "主键冲突，替换原有数据"),
    IGNORE_BY_PK(6, "主键冲突，丢弃新数据"),
    REPLACE_BY_KEY(7, "key值相同，覆盖"),
    IGNORE_BY_KEY(8, "key值相同，忽略");

    int code;
    String desc;

    OfflineSyncReplaceRuleEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static OfflineSyncReplaceRuleEnum getByCode(int code) {
        for (OfflineSyncReplaceRuleEnum value : OfflineSyncReplaceRuleEnum.values()) {
            if (Objects.equals(value.code, code)) {
                return value;
            }
        }
        return null;
    }
}
